/**
 * 给定数组A和B，需要找一段连续的子串，满足:
 * 1. SIGMA{A}不超过M
 * 2. SIGMA{B}不超过U
 * 3. 连续的长度最长
 * 尺取法，或者注意N只有5000，暴力也可以
 * 注意B可能是负数
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using pii = pair<int, int>;

int N;
llt U;
llt M;
vector<int> A, B;

inline bool isOK(int pos, llt u, llt m){
    return u + B[pos] <= U and M >= m + A[pos];
}

int proc(){
    int ans = 0;
    llt u = 0, m = 0;
    int left = 0, right = 0;
    while(1){  
        while(right < N and isOK(right, u, m)){            
            u += B[right];
            m += A[right];
            ++right;
        }
        
        ans = max(ans, right - left);
        if(right == N) break;

        if(left == right){
            ++left; ++right;
            u = m = 0LL;
        }else{
            while(1){
                u -= B[left];
                m -= A[left];
                ++left;      
                if(u <= U and m <= M) break;          
            }

        }
    }
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N >> M >> U;
    A.assign(N, 0); for(int & i : A) cin >> i;
    B.assign(N, 0); for(int & i : B) cin >> i;
    cout << proc() << endl;
    return 0;
}